package com.demo.controller;

import com.demo.domain.CtControUser;
import com.demo.domain.dto.CUserDto;
import com.demo.service.impl.CUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("ctCUser")
public class CtCUserController {
    @Autowired
    private CUserService service;

    @PostMapping("Clogin")//
    public CtControUser login(@RequestBody(required=false) CUserDto dto) throws NullPointerException {
        if (dto.getMobile() == null && dto.getMobile().equals("")) {
            System.out.println("手机号空");
            return null;
        }
        if (dto.getPassword() == null && dto.getPassword().equals("")) {
            System.out.println("密码空");
            return null;
        }
        if (dto.getAvatar() == null && dto.getAvatar().equals("")) {
            System.out.println("职位空");
            return null;
        }
        if (dto.getEmail() == null && dto.getEmail().equals("")) {
            System.out.println("邮箱空");
            return null;
        }
        CtControUser user = service.Clogin(dto.getMobile(), dto.getPassword(), dto.getAvatar(), dto.getEmail());
        if (user == null) {
            System.err.println("用户或密码错误");
            return null;
        } else {
            user.setToken("200");
            return user;
        }
    }
    @RequestMapping("CRegister")
    String register(  @RequestBody CtControUser user) {
        System.out.println("测试"+ user);
        if (service.CInsertUser(user) == null) {
            System.out.println("失败");
            return "";
        } else {
            System.out.println("成功");
            return "成功";
        }
    }
}
